package com.hibernate.springTest;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.hibernate.domain.Event;
import com.hibernate.utils.HibernateFactory;

public class TestHibernateTemplate2 {
	static Session session = null;
	static Transaction tx = null;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SessionFactory sf = HibernateFactory.buildSessionFactory();
		HibernateTemplate template = new HibernateTemplate(sf);
		Event e1 = new Event();
		e1.setName("x");
		Event e2 = new Event();
		e2.setName("y");
		
		try {
			HibernateFactory.buildSessionFactory();
			session = HibernateFactory.openSession();
			tx = session.beginTransaction();
			template.save(e1);
			template.save(e2);
			Event obj = (Event) template.load(Event.class, e1.getId());
			System.out.println("LOADED THE EVENT"+obj.getName());
			List events = template.find("from Event");
			System.out.println("# of events"+events.size());
		   tx.commit();
		} finally {
			template.delete(e1);
			template.delete(e2);
		}
	

	}
	private static void startOperation() {

	}
	

}
